<template>
  <div class="zuoye-container">
    <div class="tabs">
      <van-tabs v-model="active" @click="menuClick">
        <van-tab :title="`全部(${allTotal})`"></van-tab>
        <van-tab :title="`未付款(${noTotal})`"></van-tab>
        <van-tab :title="`已付款(${playTotal})`"></van-tab>
      </van-tabs>
    </div>
    <div class="list-group" ref="scrollbars">
      <van-list loading-text="加载中" v-model="loading" :finished="finished" :finished-text="listData.length > 0 ? '没有更多了' : ''" @load="initAjaxMethod">
        <div class="match-content" v-for="(item, index) in listData" :key="index">
          <div class="content-img-group-mobile">
            <div style="position: relative;" class="content-img-group">
              <img :src="baseUrl + item.kc_thumb" class="content-img">
            </div>
          </div>
          <div class="detail-mobile">
            <div class="detail-info">
              <span style="margin-left:0.1rem;color:#000;font-size:0.34rem;">{{ item.kc_name }}</span>
            </div>
            <div class="detail-info detail-info-flex">
              <span style="margin-left:0.1rem;color:#52B199;">¥{{ item.cose }}</span>
              <span style="color:#888;" class="icon-xiangyou1 iconfont"></span>
            </div>
            <div class="detail-info">
              <span style="margin-left:0.1rem;color:#888">开课：{{ item.kc_start | dateFrom }}</span>
            </div>
            </div>
        </div>
      </van-list>
      <empty v-if="listData.length == 0"></empty>
    </div>
  </div>
</template>
  <script>
import { PullRefresh, List, Icon, Button, Tag, Tab, Tabs, Popup } from 'vant';
import utils from "@/utils/utils";
export default {
  name: "certificate",
  components: {
    [PullRefresh.name]: PullRefresh, [List.name]: List, [Icon.name]: Icon,
    [Button.name]: Button, [Tab.name]: Tab, [Tag.name]: Tag, [Tabs.name]: Tabs, [Popup.name]: Popup
  },
  data() {
    return {
      refreshDisabled: false,
      showImg: false,
      loading: false,
      active: 0,
      allTotal: 0,
      noTotal: 0,
      playTotal: 0,
      finished: true,
      wxReadyOk: false,
      menuId: 3,
      baseUrl: this.$API.ASSET_IMAGES_URL,
      query: {
        pageIndex: 1,
        pageSize: 10
      },
      total: 0,
      listData: [],
      certificate: ''
    };
  },
  filters: {
    dateFrom(e) {
      if (!e) return '';
      return utils.dateFormat(e,null,true);
    }
  },
  mounted() {
    this.initAjaxMethod();
    this.totalAjaxMethod();
  },
  methods: {
    getDetail(item){

    },
    menuClick() {
      this.query.pageIndex = 1;
      this.listData = [];
      this.finished = false;
      this.loading = true;
      this.$refs['scrollbars'].scrollTop = 0;
      this.initAjaxMethod();
    },
    //列表加载
    initAjaxMethod() {
      const toast = this.$toast.loading("加载中...");
      this.$http
        .post(this.$API.GET_MEMBER_STUDYLIST, {
          page: this.query.pageIndex,
          pageSize: this.query.pageSize,
          status: this.active
        })
        .then((res) => {
          toast.clear();
          if (res.code == 1) {
            let list = Array.isArray(res.data.list) ? res.data.list : [];
            let isOver = list.length < this.query.pageSize ? true : false;
            this.finished = isOver;
            this.loading = false;
            this.listData = this.query.pageIndex == 1 ? list : [...this.listData, ...list];
            this.total = res.data.total;
            if (!isOver) {
              this.query.pageIndex++;
            }
          }
        });
    },
    totalAjaxMethod() {
      this.$http
        .post(this.$API.GET_MEMBER_STUDYTOTAL)
        .then((res) => {
          if (res.code == 1) {
            this.allTotal = res.all_total || 0;
            this.noTotal = res.no_total || 0;
            this.playTotal = res.play_total || 0;
          } else {
            this.$notify({ type: 'warning', message: res.msg });
          }
        });
    }
  },
};
  </script>
  <style lang="less">
  .zuoye-container {
    height: 100%;
    padding-top: 0.88rem;
    position: relative;
  
    .tabs {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
  
      .van-tabs__wrap {
        height: 0.88rem;
      }
      .van-tab__text {
        font-size: 0.32rem;
      }
     
    }
  
    .list-group {
      height: 100%;
    }
  
    .detail-tags {
      display: flex;
      justify-content: flex-end;
  
      .van-tag {
        font-size: 0.3rem;
        padding: 0.1rem 0.3rem;
        border-radius: 4px;
        line-height: 0.3rem;
      }
    }
  
    .match-content {
 
      color: #3e3a39;
      display: flex;
      // box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
      align-items: center;
      // margin-top: 0.2rem;
      cursor: pointer;
      // border-radius: 0.2rem;
      background: #fff;
      border-bottom:1px solid #eee;
      .content-img-group-mobile {
        position: relative;
        align-items: center;
        justify-content: center;
  
        .content-img-group {
          width: 1rem;
          height: 1rem;
          background: #fff;
  
          .content-img {
            width: 100%;
            height: 100%;
          }
        }
      }
  
      .detail-content-mobile {
        font-size: 0.3rem;
        color: #3e3a39;
        padding-top: 0.08rem;
      }
  
      .detail-mobile {
        width: 60%;
        padding-left: 0.3rem;
        flex-grow: 1;
      }
  
      .detail-title {
        font-size: 0.32rem;
        color: #333;
        font-weight: bold;
      }
  
      .detail-info {
        display: flex;
        align-items: center;
        padding-top: 0.1rem;
  
        span {
          font-size: 0.3rem;
          color: #3e3a39;
        }
      }
      .detail-info-flex{
        display: flex;
        align-items: center;
        justify-content: space-between;
      }
    }
  
    .bottom-button {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      padding-top: 0.2rem;
    }
  
    .popup-close-group {
      padding: 0.1rem 24%;
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
    }
    .popup-close-button {
      height: 0.7rem;
      color: #333;
      line-height: 0.7rem;
      text-align: center;
      font-size: 0.3rem;
    }
    .popup-img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
    .popup-close-header {
      font-size: 0.32rem;
      position: absolute;
      top: 0;
      left: 0;
      padding: 0 0.3rem;
      text-align: right;
      height: 1rem;
      line-height: 1rem;
      width: 100%;
    }
  }
  </style>